package com.heima.schedule.feign;

import com.heima.client.schedule.ITaskClient;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.dtos.TaskDto;
import com.heima.schedule.service.TaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
public class TaskClient implements ITaskClient {
    @Autowired
    private TaskService taskService;

    /**
     * 添加任务
     *
     * @param taskDto
     * @return
     */
    @Override
    @PostMapping("/api/v1/task/addTask")
    public ResponseResult addTask(@RequestBody TaskDto taskDto) {
        log.info("接收到消息：{}", taskDto);
        return taskService.addTask(taskDto);
    }

    /**
     * 根据任务类型和优先级来拉取任务数据
     *
     * @param taskType
     * @param priority
     * @return
     */
    @Override
    @GetMapping("/api/v1/task/{taskType}/{priority}")
    public ResponseResult pullTask(@PathVariable Integer taskType,
                                   @PathVariable Integer priority) {
        return taskService.pullTask(taskType, priority);
    }
}
